﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Data;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Imaging;
using System.Windows.Navigation;
using System.Windows.Shapes;
using Microsoft.Windows.Controls.Ribbon;
using QLGiayDep.Forms;
using ConnectToDatabase;

namespace QLGiayDep
{
    /// <summary>
    /// Interaction logic for MainWindow.xaml
    /// </summary>
    public partial class MainWindow : RibbonWindow
    {
        private string m_sMaNguoiDung;
        string URL;
        private SelectDB selectDB;

        public MainWindow()
        {
            InitializeComponent();

            // Insert code required on object creation below this point.
        }

        public MainWindow(string m_sUserName)
        {
            InitializeComponent();
            m_sMaNguoiDung = m_sUserName;
            GioiHanQuyenNguoiDung();
            mainframe.NavigationService.Navigate(new FormThongTinBanQuyen());
        }

        public MainWindow(string m_sUserName, string _URL)
        {
            InitializeComponent();
            URL = _URL;
            m_sMaNguoiDung = m_sUserName;
            selectDB = (SelectDB)Activator.GetObject(typeof(SelectDB), URL + "SELECTDB_OBJECT");
            GioiHanQuyenNguoiDung();
            mainframe.NavigationService.Navigate(new FormThongTinBanQuyen());
        }

        private void GioiHanQuyenNguoiDung()
        {
            //NV Thu Ngan
            if (selectDB.SelectMaLoaiNV_MaNV(m_sMaNguoiDung) == "LNV001")
            {
                GroupNVuKho.Visibility = Visibility.Collapsed;
                GroupBaoCao.Visibility = Visibility.Collapsed;
                btnQLNhanVien.Visibility = Visibility.Collapsed;
                btnDSNhanVien.Visibility = Visibility.Collapsed;
                
            }
            //NV Kho
            if (selectDB.SelectMaLoaiNV_MaNV(m_sMaNguoiDung) == "LNV002")
            {
                GroupNVuBanHang.Visibility = Visibility.Collapsed;
                GroupBaoCao.Visibility = Visibility.Collapsed;
                btnQLNhanVien.Visibility = Visibility.Collapsed;
                btnDSNhanVien.Visibility = Visibility.Collapsed;               
            }

        }
        
        private void btnNhaPPVSLoaiSP_Click(object sender, RoutedEventArgs e)
        {
            mainframe.NavigationService.Navigate(new FormNhaPP(URL));
        }

        private void btnNhapSanPhamMoi_Click(object sender, RoutedEventArgs e)
        {
            mainframe.NavigationService.Navigate(new NhapGiayDep(URL));
        }

        private void btnKhuyenMai_Click(object sender, RoutedEventArgs e)
        {
            mainframe.NavigationService.Navigate(new FormKhuyenMai(URL));
        }

        private void btnTraCuu_Click(object sender, RoutedEventArgs e)
        {
            mainframe.NavigationService.Navigate(new FormTraCuuSanPham(URL));
        }

        private void btnQLNhanVien_Click(object sender, RoutedEventArgs e)
        {
            mainframe.NavigationService.Navigate(new FormNhanVien(URL));
        }

        private void btnLapHoaDon_Click(object sender, RoutedEventArgs e)
        {
            //mainframe.NavigationService.Navigate(new Uri("Forms/FormHoaDon.xaml", UriKind.Relative));
            mainframe.NavigationService.Navigate(new FormHoaDon(m_sMaNguoiDung, URL));
        }

        private void btnDSNhanVien_Click(object sender, RoutedEventArgs e)
        {
            mainframe.NavigationService.Navigate(new FormDSNhanVien(URL));
        }

        private void MenuItemExit_Click(object sender, RoutedEventArgs e)
        {
            WinLogin m_winLogin = new WinLogin();
            m_winLogin.Show();
            this.Close();
        }

        private void btnAbout_Click(object sender, RoutedEventArgs e)
        {
            mainframe.NavigationService.Navigate(new Uri("Forms/FormThongTinBanQuyen.xaml", UriKind.Relative));
        }

        private void btnBCLuongHang_Click(object sender, RoutedEventArgs e)
        {
            mainframe.NavigationService.Navigate(new Uri("Forms/FormBCLuongHangNhapVao.xaml", UriKind.Relative));
        }

        private void btnBCSanPhamLoi_Click(object sender, RoutedEventArgs e)
        {
            mainframe.NavigationService.Navigate(new Uri("Forms/FormBCSanPhamLoi.xaml", UriKind.Relative));
        }

        private void btnBCSanPhamTonKho_Click(object sender, RoutedEventArgs e)
        {
            mainframe.NavigationService.Navigate(new Uri("Forms/FormBCSanPhamTonKho.xaml", UriKind.Relative));
        }

        private void btnBCDoanhThu_Click(object sender, RoutedEventArgs e)
        {
            mainframe.NavigationService.Navigate(new FormBCDoanhThu(URL));
        }

        private void btnBCDoanhThuTheoSP_Click(object sender, RoutedEventArgs e)
        {
            mainframe.NavigationService.Navigate(new Uri("Forms/FormBCDoanhThuTheoSanPham.xaml", UriKind.Relative));
        }

        private void btnXuatTraHangLoi_Click(object sender, RoutedEventArgs e)
        {
            mainframe.NavigationService.Navigate(new FormPhieuTraSP(URL));
        }

        private void btnNhapDauSanPhamMoi_Click(object sender, RoutedEventArgs e)
        {
            mainframe.NavigationService.Navigate(new FormDauSP(URL));
        }

        private void btnThongTinNhanVien_Click(object sender, RoutedEventArgs e)
        {
            mainframe.NavigationService.Navigate(new FormThongTinNhanVien(m_sMaNguoiDung, URL));
        }
    }
}
